package yz;

import java.util.Stack;

/**
 * [155. 最小栈](https://leetcode-cn.com/problems/min-stack/)
 *
 * @Author yangz
 * @Date 2022/11/14 20:53
 */
public class LeetCode155_MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> min_stack;

    public LeetCode155_MinStack() {
        stack = new Stack<>();
        min_stack = new Stack<>();
    }

    public void push(int x) {
        stack.push(x);
        if (min_stack.isEmpty() || x <= min_stack.peek()) {
            min_stack.push(x);
        }
    }

    public void pop() {
        if (stack.pop().equals(min_stack.peek())) {
            min_stack.pop();
        }

    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return min_stack.peek();
    }
}
